﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace QuanLyBanHang_N3A
{
    public partial class FormPhucHoi : Form
    {
        string filename;
        public FormPhucHoi()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnNguon_Click(object sender, EventArgs e)
        {
            OpenFileDialog f = new OpenFileDialog();
            f.Filter = "Access File (.mdb)|*.mdb";
            f.Title = "Select Database file to BackUp";
            if (f.ShowDialog() == DialogResult.OK)
                txtNguon.Text = f.FileName;
            FileInfo fi = new FileInfo(f.FileName);
            filename = fi.Name.Substring(0, fi.Name.LastIndexOf("."));
        }

        private void btnDich_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog f2 = new FolderBrowserDialog();
            if (f2.ShowDialog() == DialogResult.OK)
                txtDich.Text = f2.SelectedPath;
        }

        private void btnSaoLuu_Click(object sender, EventArgs e)
        {
            if (txtNguon.Text == "")
                MessageBox.Show("Chọn nguồn");
            else if (txtDich.Text == "")
                MessageBox.Show("Chọn Nơi Lưu Dữ Liệu");


            else
            {
                string destination;
                destination = txtDich.Text + "\\" + filename + DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + ".mdb";
                File.Copy(txtNguon.Text, destination, true);//ghi de neu trung ten

                MessageBox.Show("Phục hồi thành công");
            }
        }


    }
}
